package com.xmy.study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.study.entity.Dict;
import com.xmy.study.mapper.DictMapper;
import com.xmy.study.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2023-09-08
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {

    @Autowired
    DictMapper dictMapper;

    @Override
    public Dict getDictByNumAndType(Integer num,Integer type){
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("num",num);
        dictQueryWrapper.eq("type",type);
        dictQueryWrapper.last("limit 1");
        return dictMapper.selectOne(dictQueryWrapper);
    }

    @Override
    public String getDictNameByNumAndType(Integer num,Integer type){
        QueryWrapper<Dict> dictQueryWrapper = new QueryWrapper<>();
        dictQueryWrapper.eq("num",num);
        dictQueryWrapper.eq("type",type);
        dictQueryWrapper.last("limit 1");
        Dict dict = dictMapper.selectOne(dictQueryWrapper);
        String dictName = "";
        if (dict != null){
            dictName = dict.getName();
        }
        return dictName;
    }
}
